package com.enjoyor.soa.traffic.server.tpcms.dubbo.impl;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.enjoyor.soa.traffic.api.dto.tpcms.TemplateDto;
import com.enjoyor.soa.traffic.api.service.dubbo.tpcms.IDubboTemplateService;
import com.enjoyor.soa.traffic.core.tpcms.domain.Template;
import com.enjoyor.soa.traffic.core.tpcms.service.ITemplateExampleService;
import com.enjoyor.soa.traffic.server.tpcms.dubbo.invoke.DubboTokenServiceInvoke;
import com.enjoyor.soa.traffic.util.helper.ReflectHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

@SuppressWarnings("rawtypes")
@Service(version = "1.0.0", timeout = 4000)
public class DubboTemplateService implements IDubboTemplateService {

    @Autowired
    private ITemplateExampleService templateExampleService;

    @Autowired
    private DubboTokenServiceInvoke dubboTokenServiceInvoke;

    public ResultPojo select(String id) {
        return new ResultPojo(templateExampleService.select(id));
    }

    public ResultPojo insert(TemplateDto template, String userName) {
        templateExampleService.insert(ReflectHelper.beanToBean(template, Template.class), userName);
        return new ResultPojo();
    }

    public ResultPojo edit(TemplateDto template, String userName) {
        templateExampleService.edit(ReflectHelper.beanToBean(template, Template.class), userName);
        return new ResultPojo();
    }

    public ResultPojo delete(String id, String userName) {
        templateExampleService.delete(id, userName);
        return new ResultPojo();
    }

    @Override
    public ResultPojo selectPage(Page page) {
        return new ResultPojo(templateExampleService.selectPage(page));
    }

    @Override
    public ResultPojo check(String token, String sysKey) {
        return new ResultPojo(dubboTokenServiceInvoke.check(token, sysKey));
    }

}
